package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcTest1 {

	public static void main(String[] args) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
			return;
		}
		String url = "jdbc:mysql://localhost:3306/java46?useUnicode=true&characterEncoding=utf8";
		try {
			Connection con = DriverManager.getConnection(url, "suncy", "suncy");
			System.out.println("Connection实现类：" + con.getClass().getName());
			Statement st = con.createStatement();
			System.out.println("Statement:" + st.getClass().getName());
			ResultSet rs = st.executeQuery("select * from grade");
			while (rs.next()) {
				int id = rs.getInt("id");
				String gname = rs.getString("gname");
				System.out.println(id + "," + gname);
			}
			rs.close();
			st.close();
			con.close();
		} catch (SQLException e) {
			System.out.println("链接失败！");
			e.printStackTrace();
		}

	}

}
